package com.itzb.asone.fileserver.channel;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.itzb.asone.fileserver.model.FSResult;

public abstract class IChannelService {
	
	/**
     * 获取目录
     * @return
     */
	abstract public FSResult getFileList(String path);
	
	/**
     * 目录删除
     * @param path
     * @return
     */
	abstract public FSResult deleteFolder(String path);
	
	/**
     * 文件上传
     * @param path
     * @return
     */
	abstract public FSResult uploadFile(String filePath,String fileName);
	
	/**
     * 文件删除
     * @param path
     * @return
     */
	abstract public FSResult deleteFile(String filePath);
	
	
	public String getUploadPath(String fileName){
		
		SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
		Date dt=new Date();
		
		String image = "JPG|JPEG|BMP|GIF|PNG";
		String world = "DOC|DOCX";
		String excel = "XLS|XLSX";
		String txt = "TXT";
		
		String path = "";
		String fileType = fileName.split("\\.")[1];
		if(image.indexOf(fileType.toUpperCase()) >= 0){
			path = "/image/" + format.format(dt) + "/" + fileName;
		} else if(world.indexOf(fileType.toUpperCase()) >= 0){
			path = "/world/" + format.format(dt) + "/" + fileName;
		} else if(excel.indexOf(fileType.toUpperCase()) >= 0){
			path = "/excel/" + format.format(dt) + "/" + fileName;
		} else if(txt.indexOf(fileType.toUpperCase()) >= 0){
			path = "/txt/" + format.format(dt) + "/" + fileName;
		} else {
			path = "/oth/" + format.format(dt) + "/" + fileName;
		}
		
		return path;
	}
	
	
}
